package com.lineng.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lineng.pojo.DownTable;
import com.lineng.service.DownTableService;

@Controller
public class DownTableController {

	@Autowired
	DownTableService downTableService;

	/**
	 * 获取获取表格
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getDownTable", method = RequestMethod.GET, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getDownTable() {
		List<DownTable> downtables = downTableService.getDownTable();
		return JSON.toJSONString(downtables);

	}

	/**
	 * 添加表格
	 * 
	 * @param downtable
	 * @return
	 */
	@RequestMapping(value = "/insertDownTable", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String insertDownTable(DownTable downtable, HttpServletRequest request) {
		return JSON.toJSONString(
				downTableService.insertDownTable(downtable, (String) request.getSession().getAttribute("username")));

	}

	/**
	 * 更改表格
	 * 
	 * @param downtable
	 * @return
	 */
	@RequestMapping(value = "/updateDownTable", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String updateDownTable(DownTable downtable, HttpServletRequest request) {
		return JSON.toJSONString(
				downTableService.updateDownTable(downtable, (String) request.getSession().getAttribute("username")));

	}

	/**
	 * 删除表格
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/deleteDownTable", method = RequestMethod.POST, produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String deleteDownTable(Integer[] idList) {
		return JSON.toJSONString(downTableService.deleteDownTable(idList));

	}

}
